<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据类型</title>
  <script>
    function f1(){
      let i=1;
      //number
      console.log(typeof i);
      i="admin";
      //string
      console.log(typeof i)
      i=true;
      //boolean
      console.log(typeof i)
      i='a';
      //string
      console.log(typeof i)
    }
    function f2(){
      //声明变量未赋值
      let name;
      console.log(typeof name)
      name = null;
      //object
      console.log(typeof name);
      name = undefined;
      //undefined
      console.log(typeof name);
      name = NaN;     // Not a Number
      console.log(typeof name);
      let i = "a";
      // a无法被解析为有效整数
      i = parseInt(i);
      console.log(i);
    }
    function f3(){
      //所有都是继承自object
      let obj = new Object();
      console.log(typeof obj)
      let arr = [1,2,3];
      console.log(typeof arr)
      let date = new Date();
      console.log(date);
      console.log(typeof date)
    }
    function f4(){
      // 不带括号,表示将指定函数作为整体赋值给变量
      // 此时变量的类型是一个函数类型
      let i = fn;
      // alert(fn)
      console.log(typeof i);
      // 如果带括号,则表示先执行对应函数,将函数的返回值赋值给对应变量
      // 此时变量的类型是函数返回值的类型
      let name = fn();
      alert(name)
    }
    function fn(){
      return "admin";
    }
  </script>
</head>
<body>
<button onclick="f1()">基本数据类型</button><br>
<button onclick="f2()">非基本数据类型</button><br>
<button onclick="f3()">复合类型</button><br>
<button onclick="f4()">函数类型</button>
</body>
</html>